﻿<Window x:Class="TorchView.Shell.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TorchView.Shell" xmlns:tvw="clr-namespace:TorchView.Windows;assembly=TorchView.Common" FontFamily="Arial" Title="TorchView" Background="Black" MinWidth="900" Width="900" Height="600" MinHeight="600" WindowStyle="None" ResizeMode="CanResizeWithGrip">
  <Window.Resources>
  </Window.Resources>
  <Grid Margin="2">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
      <RowDefinition Height="Auto" MinHeight="10" />
    </Grid.RowDefinitions>
    <Image Source="/TorchView;Component/views/images/Torchlight Background Art.png" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="10" />
    <Menu Background="{x:Null}" VerticalContentAlignment="Center">
      <Menu.Resources>

        <!-- TopLevelHeader -->
        <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="MenuItem">
          <Border Name="Border" CornerRadius="2">
            <Grid>
              <ContentPresenter Margin="6,4" ContentSource="Header" RecognizesAccessKey="True" />
              <Popup Name="Popup" Placement="Bottom" VerticalOffset="1" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade" MinWidth="60">
                <Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="{StaticResource BackgroundBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
                  <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                </Border>
              </Popup>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
              <Setter TargetName="Popup" Property="PopupAnimation" Value="None" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="Transparent" />
            </Trigger>
            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
              <Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="2" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>

        <!-- TopLevelItem -->

        <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="MenuItem">
          <Border Name="Border" CornerRadius="2">
            <Grid>
              <ContentPresenter Margin="6,4" ContentSource="Header" RecognizesAccessKey="True" />
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
              <Setter TargetName="Border" Property="BorderBrush" Value="Transparent" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>

        <!-- SubmenuItem -->

        <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="MenuItem">
          <Border Name="Border">
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="Icon" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="13" />
              </Grid.ColumnDefinitions>
              <ContentPresenter Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon" />
              <Border Name="Check" Width="13" Height="13" Visibility="Collapsed" Margin="6,0,6,0">
                <Path Name="CheckMark" Width="7" Height="7" Visibility="Hidden" SnapsToDevicePixels="False" Stroke="LightGray" StrokeThickness="2" Data="M 0 0 L 7 7 M 0 7 L 7 0" />
              </Border>
              <ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header" RecognizesAccessKey="True" Margin="0,4" />
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
              <Setter TargetName="Icon" Property="Visibility" Value="Hidden" />
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
              <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsCheckable" Value="true">
              <Setter TargetName="Check" Property="Visibility" Value="Visible" />
              <Setter TargetName="Icon" Property="Visibility" Value="Hidden" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>

        <!-- SubmenuHeader -->

        <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="MenuItem">
          <Border Name="Border">
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="Icon" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="13" />
              </Grid.ColumnDefinitions>
              <ContentPresenter Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon" />
              <ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header" RecognizesAccessKey="True" Margin="0,4" />
              <Path Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 0 7 L 4 3.5 Z" Fill="LightGray" />
              <Popup Name="Popup" Placement="Right" HorizontalOffset="-4" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
                <Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="{StaticResource BackgroundBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
                  <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                </Border>
              </Popup>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
              <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="true">
              <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
            </Trigger>
            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
              <Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="4" />
              <Setter TargetName="SubmenuBorder" Property="Padding" Value="0,3,0,3" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>

        <Style TargetType="MenuItem">
          <Setter Property="Foreground" Value="{StaticResource UnhighlightedTextBrush}" />
          <Setter Property="OverridesDefaultStyle" Value="True" />
          <Style.Triggers>
            <Trigger Property="Role" Value="TopLevelHeader">
              <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}" />
              <Setter Property="Grid.IsSharedSizeScope" Value="true" />
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
              <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelItemTemplateKey}}" />
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
              <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}" />
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
              <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter Property="Foreground" Value="{StaticResource HighlightedTextBrush}" />
            </Trigger>
          </Style.Triggers>

        </Style>
      </Menu.Resources>
      <MenuItem Header="TorchView">
        <MenuItem Header="Launch Torchlight" Command="{Binding LaunchTorchlightCommand}" />
        <MenuItem Header="Exit" Command="{Binding CloseCommand}" /> 
      </MenuItem>
      <MenuItem Header="Help">
        <MenuItem Header="About TorchView" Command="{Binding AboutCommand}" />
      </MenuItem>
    </Menu>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.ColumnSpan="2">
      <StackPanel.Resources>
        <Style TargetType="Button">
          <Setter Property="Margin" Value="2" />
          <Setter Property="Foreground" Value="{StaticResource UnhighlightedTextBrush}" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="Button">
                <Border Background="Transparent" Padding="2">
                  <ContentPresenter />
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
          <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter Property="Foreground" Value="{StaticResource HighlightedTextBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
          </Style.Triggers>
        </Style>
        <Style TargetType="Polyline">
          <Setter Property="Stretch" Value="None" />
          <Setter Property="Width" Value="10" />
          <Setter Property="Height" Value="10" />
          <Setter Property="StrokeThickness" Value="2" />
          <Setter Property="Stroke" Value="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" />
        </Style>
      </StackPanel.Resources>

      <Button Command="{x:Static tvw:WindowService.MinimizeWindow}">
        <Polyline Points="0,9 10,9" />
      </Button>
      <Button Command="{x:Static tvw:WindowService.MaximizeWindow}">
        <Polyline Points="10,0 0,0 0,10 10,10 10,1 0,1" />
      </Button>
      <Button Command="{Binding CloseCommand}">
        <Polyline Points="0,0 10,10 5,5 10,0 0,10" />
      </Button>
    </StackPanel>
    <TabControl SelectedIndex="0" ItemsSource="{Binding Plugins}" Grid.Row="1" Background="{x:Null}" BorderThickness="0" HorizontalContentAlignment="Stretch">
      <TabControl.ItemContainerStyle>
        <Style TargetType="TabItem">
          <Setter Property="Header" Value="{Binding Name}" />
          <Setter Property="Content" Value="{Binding MainView}" />
          <Setter Property="Foreground" Value="{StaticResource UnhighlightedTextBrush}" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type TabItem}">
                <Grid Background="Transparent">
                  <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="6,2" RecognizesAccessKey="True" />
                </Grid>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
          <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
              <Setter Property="Foreground" Value="{StaticResource HighlightedTextBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
          </Style.Triggers>
        </Style>
      </TabControl.ItemContainerStyle>
      <TabControl.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding}" FontSize="20" />
        </DataTemplate>
      </TabControl.ItemTemplate>
    </TabControl>
  </Grid>
</Window>